package com.oa.srms.apps.business.goods.impl;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import com.oa.srms.apps.business.goods.IGoodCategoryService;
import com.oa.srms.apps.constants.IDEDStates;
import com.oa.srms.apps.dao.goods.IGoodCategoryDao;
import com.oa.srms.apps.entity.goods.GoodCategoryValue;

public class GoodCategoryServiceImpl implements IGoodCategoryService {
	@Autowired
	private GoodCategoryValue goodCategory;
	@Autowired
	private IGoodCategoryDao goodCategoryDao;
	
	@Override
	public int addGoodCategory(String categoryNo, String categoryName)
			throws Exception {
		goodCategory.setCategoryNo(categoryNo);
		goodCategory.setCategoryName(categoryName);
		goodCategory.setStates(IDEDStates.ENABLE);
		return goodCategoryDao.addGoodCategory(goodCategory);
	}

	@Override
	public boolean modifyGoodCategory(Integer categoryId, String categoryNo,
			String categoryName) throws Exception {
		goodCategory=this.quaryByCategoryId(categoryId);
		if(goodCategory!=null){
			goodCategory.setCategoryNo(categoryNo);
			goodCategory.setCategoryName(categoryName);
			goodCategoryDao.editGoodCategory(goodCategory);
		}else{
			return false;
		}
		return true;
	}

	@Override
	public boolean deleteGoodCategory(Integer categoryId) throws Exception {
		goodCategory=this.quaryByCategoryId(categoryId);
		if(goodCategory!=null){
			goodCategory.setStates(IDEDStates.DELETE);
			goodCategoryDao.editGoodCategory(goodCategory);
		}else{
			return false;
		}
		return true;
	}

	@Override
	public GoodCategoryValue quaryByCategoryId(Integer categoryId)
			throws Exception {
		goodCategory.setCategoryId(categoryId);
		return goodCategoryDao.quaryByCategoryId(goodCategory);
	}

	@Override
	public List<GoodCategoryValue> quaryGoodCategoryValue(Integer states) throws Exception {
		return goodCategoryDao.quaryGoodCategoryValue(states);
	}

	@Override
	public boolean toEnable(Integer categoryId) throws Exception {
		goodCategory=this.quaryByCategoryId(categoryId);
		if(goodCategory!=null){
			goodCategory.setStates(IDEDStates.ENABLE);
			goodCategoryDao.editGoodCategory(goodCategory);
		}else{
			return false;
		}
		return true;
	}

	@Override
	public boolean toDisable(Integer categoryId) throws Exception {
		goodCategory=this.quaryByCategoryId(categoryId);
		if(goodCategory!=null){
			goodCategory.setStates(IDEDStates.DISABLE);
			goodCategoryDao.editGoodCategory(goodCategory);
		}else{
			return false;
		}
		return true;
	}



}
